package com.example.sxy.opcuademo;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;


public class MainActivity extends Activity {
    private Button btn;
    private TextView value_tx;
//    服务器地址 TCP 或者  https地址
    private String []serverUris={"opc.tcp://192.168.88.201:52520/OPCUA/SampleConsoleServer"};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        value_tx = (TextView) findViewById(R.id.value_text);
        btn = (Button) findViewById(R.id.btn);
//        添加监听事件，开启异步任务请求OPCServer
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                创建异步任务
                ConnectAndReadTimeTask task = new ConnectAndReadTimeTask(MainActivity.this, "DemoAppForAndroid");
//                传入参数为服务器地址
                task.execute(serverUris);
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    /**
     * @param value
     * 改变TextView内的值
     */
    public void setValue(String value)
    {
        value_tx.setText(value);
    }
}
